
Use it to prevent robots from crashing, detect people approaching and much more!
Watch this video for a complete tutorial:
Connect the special cable to the ultrasonic sensor. The red wire should connect to the VCC pin:
Attach the cable to the Edge Connector or Motor Controller board as follows:
Ultrasonic | Microbit | Purpose |
---|---|---|
Trig (white wire) | P14 | Trig (make an ultrasound signal) |
Echo (brown wire) | P16 | Echo (listen for an ultrasound signal) |
You don't have to use pins P14 and P16. You can use any digital pin. Just remember to adjust your code accordingly.
Add this extension:
Enter this code in forever:
The Serial blocks can be found in Advanced.
Download the code to the microbit.
To see the data, click on Show data Device:
You should see some numbers and a graph. These show the distance readings in cm. Place you hand in front of the sensor and move it back and forth. The readings should show how far your hand is from the sensor.
You could also try this, to show when an object approaches close to the sensor: